Eddie's Lessons, version 11

Saving and Loading Files in Rich Text Format

level: any

by Alyce Watson [http://alycesrestaurant.com/]

NL42 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

API Corner

Technical Writing

Eddie V11

Sub Event Handlers

Comboboxes / Hot Keys

Wire - Reminders / Tips

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index


What is Eddie?

Eddie is a new code editor written in Liberty BASIC, for Liberty BASIC. Eddie can be customized and extended to meet the needs of the individual programmer. The newest version is available in the zipped archive of this issue.


What is Rich text Format?

Rich Text Format, also known as RTF allows text to be displayed in multiple colors, font faces, font styles, and font sizes. It is the method used in the CodeAChrome DLL to do the syntax coloring of code that makes keywords one color, quoted text another color, etc.

syntax color

Why Save in Rich Text Format?

Large files load into CodeAChrome more quickly if they've been saved as RTF files, since CodeAChrome does not need to parse and do syntax coloring. Files saved as RTF can also be loaded into your favorite RTF editor. Try saving a source code file in RTF with Eddie, then open it in Wordpad. You'll see that the syntax coloring has been preserved. If you open a regular source code file in Wordpad, Word, etc. it is displayed as plain text.

Saving RTF Files in Eddie

CodeAChrome has a function that saves the contents to disk as an RTF file. It is called FileSaveAsRTF. It looks like this:

    calldll #r, "FileSaveAsRTF",_    'save contents to disk
    savefile$ as ptr,_      'save filename
    re as void

The routine to save files in RTF looks very similar to the routine that saves them as plain text. Eddie v11 adds the following code, which is accessed by a new menu item in the File Menu.

[saveRTF]   'save in rich text format
    filedialog "Save As",Curdir$ + "\*.rtf",savefile$
    if savefile$="" then wait

    'make sure that user had given the file a *rtf extension
    if right$(lower$(savefile$),4)<>".rtf" then
        savefile$=savefile$+".rtf"
    end if

    Curdir$ = SeparatePath$(savefile$)

    calldll #r, "FileSaveAsRTF",_    'save contents to disk
    savefile$ as ptr,_      'save filename
    re as void
    Wait

Loading RTF Files in Eddie

Once a file has been saved as an RTF file, it can be reloaded later. The function is called FileLoadAsRTF and it opens the named file and places the contents into the CodeAChrome control. Eddie adds an option to the File Menu to Open As RTF, and the routine looks like this:

[openRTF]   'open a rich text file and load into Eddie
    filedialog "Open",Curdir$ + "\*.rtf",openfile$
    if openfile$="" then wait

    Curdir$ = SeparatePath$(openfile$)

    calldll #r, "FileLoadAsRTF",_    'load file into codeachrome
    openfile$ as ptr,_  'name of file
    re as void          'no return

    gosub [fillBranch]
    Wait


There's More!

Watch for more features of CodeAChrome in future versions of Eddie.


NL42 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

API Corner

Technical Writing

Eddie V11

Sub Event Handlers

Comboboxes / Hot Keys

Wire - Reminders / Tips

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index